package com.wuliang.generate.common.core.configs;

import com.alibaba.druid.pool.DruidDataSource;
import com.wuliang.generate.common.core.properties.DataSourceConfigProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.orm.jpa.JpaVendorAdapter;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;

import javax.sql.DataSource;

/**
 * @author WuLiang
 */
@Slf4j
@Configuration
@EnableConfigurationProperties(DataSourceConfigProperties.class)
public class DatasourceConfig {

    private DataSourceConfigProperties dataSourceConfigProperties;

    @Autowired
    DatasourceConfig(DataSourceConfigProperties dataSourceConfigProperties) {
        this.dataSourceConfigProperties = dataSourceConfigProperties;
    }

    @Bean(name = "datasourceDataSource")
    @Qualifier("datasourceDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.datasource")
    public DataSource datasourceDataSource() {
        return new DruidDataSource();
    }

    @Bean(name = "authorDataSource")
    @Qualifier("authorDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.author")
    public DataSource authorDataSource() {
        return new DruidDataSource();
    }

    @Bean(name = "systemDataSource")
    @Qualifier("systemDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.system")
    public DataSource systemDataSource() {
        return new DruidDataSource();
    }

}
